<template>
    <el-container class="home">
        <el-header>
            <div>
                <img src="../assets/技术.png" alt="">
                <span>电商后台管理系统</span>
            </div>
            <el-button type="info" @click="rem">退出</el-button>
        </el-header>
        <el-container class="main">
            <el-aside :width="istaggle ? '64px':'200px'">
                <div class="btn" @click="clickTaggle">|||</div>
                <el-menu background-color="rgb(55,61,65)"
                        text-color="#fff"
                        active-text-color="rgb(64,158,255)"
                        width="198px"
                :unique-opened="true"
                :collapse="istaggle"
                :collapse-transition="false"
                :default-active="activeNav" router>
                    <el-submenu :index="item.id+''" width="200px" v-for="item in menuList" :key="item.id" >
                        <template slot="title">
                            <i :class="iconsObject[item.id]"></i>
                            <span>{{item.authName}}</span>
                        </template>
                        <el-menu-item v-for="subItem in item.children" :key="subItem.id" :index="'/'+subItem.path" @click="saveStateNav('/'+subItem.path)">
                            <template slot="title">
                                <i class="el-icon-menu"></i>
                                <span>{{subItem.authName}}</span>
                            </template>
                        </el-menu-item>
                    </el-submenu>
                </el-menu>
            </el-aside>
            <el-main>

                <router-view/>

            </el-main>
        </el-container>
    </el-container>
</template>

<script>
    export default {
        name: "home",
        created() {
          this.getMenuList();
          this.activeNav=window.sessionStorage.getItem('activeNav');
        },
        data(){
            return{
                menuList:[],
                iconsObject:{
                    "125":'el-icon-user',
                    '103':'el-icon-s-cooperation',
                    "101":"el-icon-goods",
                    "102":"el-icon-s-order",
                    "145":"el-icon-data-analysis"
                },
                istaggle:false,
                activeNav:''
            }
        },
        methods:{
            rem(){
                window.sessionStorage.clear();
                this.$router.push('/login');
            },
            getMenuList(){
                this.$http.get("menus").then(res=>{
                    if(res.data.meta.status!==200) return this.$message.error(res.data.meta.msg);
                    this.menuList=res.data.data;
                    // console.log(res);
                    // console.log(this.menuList);
                })
            },
            clickTaggle(){
                this.istaggle=!this.istaggle;
            },
            saveStateNav(activeNav){
                window.sessionStorage.setItem("activeNav",activeNav);
                this.activeNav=activeNav;
            }

        }
    }
</script>

<style lang="less" scoped>
    .home{
        height: 100vh;
        .el-header{
            background-color: rgb(55,61,65);
            display: flex;
            justify-content: space-between;
            padding-left: 10px;
            align-items: center;
            color: white;
            font-size: 20px;
            div{
                display: flex;
                align-items: center;
                justify-content: space-between;
                width: 250px;
                img{
                    height: 50px;
                    width: 50px;
                }
            }
        }
        .el-aside{
            background-color: rgb(55,61,65);
            transition: 500ms ease-in-out;
            .el-menu{
                /*width: 100%;*/
                border: none;
            }
        }
        .el-main{
            background-color: rgb(234,237,241);
            /*padding: 0;*/
            margin: 0;
            padding: 10px 30px;
            background: url("../assets/bgimg.jpg") no-repeat;
            background-size: cover;
            box-sizing: border-box;

        }

    }
    .btn {
        background-color: rgb(71, 81, 99);
        text-align: center;
        color: white;
        font-size: 10px;
        line-height: 24px;
        letter-spacing: 2px;
        cursor: pointer;
    }

</style>
